luci-compat: CBI skip fields that do not satisfy depends
authorLiangbin Lian <[email protected]>
Tue, 10 Dec 2024 09:39:29 +0000 (17:39 +0800)
committerPaul Donald <[email protected]>
Wed, 3 Dec 2025 20:51:32 +0000 (21:51 +0100)
If depends is not satisfied, the fvalue will be nil.

Signed-off-by: Liangbin Lian <[email protected]>
modules/luci-compat/luasrc/cbi.lua

index 450e413916774669e9e7c4bca75247ab6c25c407..5f7524be11ae80c7929dee75b02160de10739a88 100644 (file)
@@ -1456,7 +1456,7 @@ function AbstractValue.parse(self, section, novld)
                                        --luci.util.append(self.map.events, self.events)
                                end
                        end
-               elseif cvalue ~= fvalue and not novld then
+               elseif (fvalue ~= nil or self.nilasempty) and cvalue ~= fvalue and not novld then
                        -- trigger validator with nil value to get custom user error msg.
                        local _, val_err = self:validate(nil, section)
                        self:add_error(section, "missing", val_err)
@@ -1695,6 +1695,7 @@ function MultiValue.__init__(self, ...)
 
        self.widget = "checkbox"
        self.delimiter = " "
+       self.nilasempty = true
 
        self:reset_values()
 end
@@ -1785,6 +1786,7 @@ function DynamicList.__init__(self, ...)
        AbstractValue.__init__(self, ...)
        self.template  = "cbi/dynlist"
        self.cast = "table"
+       self.nilasempty = true
        self:reset_values()
 end